package com.sxkiler.demo.test.mongodb;

import com.sxkiler.demo.test.common.config.MongoDbConfig;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

/**
 * 访问前端mongo的数据库
 */
@Configuration(value = "helpMongoConfig")
@ConfigurationProperties(prefix="spring.help.mongodb")
@ConditionalOnProperty(prefix = "spring.help.mongodb",name = "host")
public class HelpMongoConfiguration extends MongoDbConfig {

    @Bean(name="helpMongoTemplate")
    public MongoTemplate getMongoTemplate(@Qualifier("helpMongoConfig") MongoDbConfig mongoDbConfig) {
        return new MongoTemplate(mongoDbConfig.mongoDbFactory());
    }
}
